<template>
  <a-modal title="请选择流程退回节点" width='600px' :visible.sync="dialogTaskBackNodesInChild" @cancel="handleCancel" @ok="handlerSubmit">
    <a-radio-group v-model="backNode" @change="selectBackNode">
      <a-radio v-for="(item,index) in backNodes" :value="item" :key='index'>
        {{item.nodeName}} {{item.userName}}
      </a-radio>

    </a-radio-group>
    <br/><br/>
    <a-textarea placeholder="请输入退回原因" allow-clear v-model="message"/>
  </a-modal>
</template>

<script>
  import api from './js/api'

  export default {
    name: 'TaskbackModel',
    props: {
      visible: {
        type: Boolean,
        default: function() {
          return false
        }
      },
      executeTaskId: {
        type: String,
        default: function() {
          return ''
        }
      }
    },
    computed: {
      dialogTaskBackNodesInChild: {
        get() {
          return this.visible
        },
        set(val) {
          this.$emit('update:visible', val)
        }
      }
    },
    data() {
      return {
        api: Object.assign(api, this.api),
        backNode: {},
        message:'',
        backNodes: []
      }
    },
    created() {
      this.initData()
    },
    methods: {
      handleCancel() {
        this.dialogTaskBackNodesInChild = false
      },
      initData() {
        this.http.get(this, {
          url: this.api.tasktodo.getBackNodes,
          params: {
            taskId: this.executeTaskId
          },
          success: function(me, data) {
            me.backNodes = data
            me.backNode = me.backNodes[0]
          }
        })
      },
      selectBackNode(e) {
        this.backNode = e.target.value
      },
      handlerSubmit() {
        this.dialogTaskBackNodesInChild = false
        this.$emit('backTaskSubmit', this.backNode,this.message)
      }
    }
  }
</script>

